﻿using OMR.EasyBackup.Core.BackupManagers;
using OMR.EasyBackup.Core.BackupManagers.SQL;
using OMR.EasyBackup.Core.EventArguments;
using OMR.EasyBackup.Core.Watchers;
using System;

namespace OMR.EasyBackup.ClientDemo
{
    class Program
    {
        static IBackupManager sqlBackup;
        static Guid userId;

        static void Main(string[] args)
        {
            sqlBackup  = new SqlServerBackupManager();
            userId = new Guid("51091ec7-73b5-4409-bb40-732df0e4e5cd");

            WatcherBase w = new FSWatcher(@"c:\SampleCriticalDirectory\", "*.*");
            w.OnFileCreated += onFileCreated;
            w.OnFileRenamed += onFileRenamed;
            w.OnFileDeleted += onFileDeleted;
            w.OnFileContentChanged += onFileContentChanged;

            w.Start();

            Console.WriteLine("My eyes on you...");
            Console.ReadKey();

            w.Stop();
        }

        private static void onFileDeleted(object sender, FileDeletedEventArgs e)
        {
            sqlBackup.Delete(userId, e.FullPath);
        }

        private static void onFileContentChanged(object sender, FileContentChangedEventArgs e)
        {
            Console.WriteLine("content changed");
            sqlBackup.Update(userId, e.FullPath, e.Content);
        }

        private static void onFileRenamed(object sender, FileRenamedEventArgs e)
        {
            sqlBackup.Rename(userId, e.OldFullPath, e.NewFullPath);
        }

        private static void onFileCreated(object sender, FileCreatedEventArgs e)
        {
            sqlBackup.Create(userId, e.FullPath, e.Content);
        }

    }
}
